package drds.common.db.xml_mapping.parameter_and_result_value_type;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class IntegerTypeHandler extends BaseTypeHandler<Integer> {

  @Override
  public void setNonNullParameter(PreparedStatement preparedStatement, int index, Integer parameter, JdbcType jdbcType)
    throws SQLException {
    preparedStatement.setInt(index, parameter);
  }

  @Override
  public Integer getNullableResult(ResultSet resultSet, String columnName)
    throws SQLException {
    int result = resultSet.getInt(columnName);
    return result == 0 && resultSet.wasNull() ? null : result;
  }

  @Override
  public Integer getNullableResult(ResultSet resultSet, int columnIndex)
    throws SQLException {
    int result = resultSet.getInt(columnIndex);
    return result == 0 && resultSet.wasNull() ? null : result;
  }


}
